﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CuaHangMayTinh.Utilities;
using CuaHangMayTinh.DataProvider;
using CuaHangMayTinh.BusinessEntities;
using CuaHangMayTinh.DataAccessLayer;
using System.Data;

namespace CuaHangMayTinh.BusinessLogicLayer
{
    /// <summary>
    /// Lớp ModelMatHangManager
    /// </summary>
    public class ModelMatHangManager
    {
        private static ModelMatHangDA adapter = null;

        static ModelMatHangManager()
        {
            if (adapter == null)
                adapter = new ModelMatHangDA();
        }

        /// <summary>
        /// Hàm thêm 1 moodel mặt hàng mới
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int Insert(ModelMatHangEntity entity)
        {
            try
            {
                return adapter.Insert(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// Hàm thêm 1 moodel mặt hàng mới
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static int Insert(ModelMatHangEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.Insert(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// Hàm Thêm 1 model mới, trả về ID
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int InsertGetID(ModelMatHangEntity entity)
        {
            try
            {
                return adapter.InsertGetID(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// Hàm Thêm 1 model mới, trả về ID
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static int InsertGetID(ModelMatHangEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.InsertGetID(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// Hàm cập nhật thông tin model mặt hàng
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool UpDate(ModelMatHangEntity entity)
        {
            try
            {
                return adapter.UpDate(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// Hàm cập nhật thông tin model mặt hàng
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static bool UpDate(ModelMatHangEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.UpDate(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// Hàm cập nhật trạng thái model mặt hàng
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool Update_TinhTrang(ModelMatHangEntity entity)
        {
            try
            {
                return adapter.Update_TinhTrang(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// Hàm cập nhật trạng thái model mặt hàng
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static bool Update_TinhTrang(ModelMatHangEntity entity, ref string errormessage)
        {
            try
            {
                return adapter.Update_TinhTrang(entity);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// Hàm tìm tất cả thông tin của model mặt hàng
        /// </summary>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_All(bool View)
        {
            try
            {
                return adapter.Find_All(View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// Hàm tìm tất cả thông tin của model mặt hàng
        /// </summary>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_All(bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_All(View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// Hàm tìm ID model mặt hàng
        /// </summary>
        /// <param name="hang"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int GetID(string hang, string model)
        {
            try
            {
                return adapter.GetID(hang, model);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// Hàm lấy giá của model mặt hàng
        /// </summary>
        /// <param name="MaModelMH"></param>
        /// <returns></returns>
        public static decimal GetGia(int MaModelMH)
        {
            try
            {
                return adapter.GetGia(MaModelMH);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_Model(string model, bool View)
        {
            try
            {
                return adapter.Find_Model(model, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_Model(string model, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_Model(model, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="hang"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_HangSX(string hang, bool View)
        {
            try
            {
                return adapter.Find_HangSX(hang, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="hang"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_HangSX(string hang, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_HangSX(hang, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="loai"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_TenLoaiMH(string loai, bool View)
        {
            try
            {
                return adapter.Find_TenLoaiMH(loai, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="loai"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_TenLoaiMH(string loai, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_TenLoaiMH(loai, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="maloai"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_MaLoaiMH(int maloai, bool View)
        {
            try
            {
                return adapter.Find_MaLoaiMH(maloai, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="maloai"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_MaLoaiMH(int maloai, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_MaLoaiMH(maloai, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="hang"></param>
        /// <param name="model"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_Hang_Model(string hang, string model, bool View)
        {
            try
            {
                return adapter.Find_Hang_Model(hang, model, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="hang"></param>
        /// <param name="model"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_Hang_Model(string hang, string model, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_Hang_Model(hang, model, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="MaHoaDonBan"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_MaHoaDonBan(int MaHoaDonBan, bool View)
        {
            try
            {
                return adapter.Find_MaHoaDonBan(MaHoaDonBan, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="MaHoaDonBan"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_MaHoaDonBan(int MaHoaDonBan, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_MaHoaDonBan(MaHoaDonBan, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="maHoaDonNhap"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_MaHoaDonNhap(int maHoaDonNhap, bool View)
        {
            try
            {
                return adapter.Find_MaHoaDonNhap(maHoaDonNhap, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="MaHoaDonNhap"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_MaHoaDonNhap(int MaHoaDonNhap, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_MaHoaDonNhap(MaHoaDonNhap, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="View"></param>
        /// <returns></returns>
        public static DataTable Find_ID(int id, bool View)
        {
            try
            {
                return adapter.Find_ID(id, View);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="View"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static DataTable Find_ID(int id, bool View, ref string errormessage)
        {
            try
            {
                return adapter.Find_ID(id, View);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static DataTable Find_Info_Ban()
        {
            try
            {
                return adapter.Find_Info_Ban();
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool Delete(int id)
        {
            try
            {
                return adapter.Delete(id);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="errormessage"></param>
        /// <returns></returns>
        public static bool Delete(int id, ref string errormessage)
        {
            try
            {
                return adapter.Delete(id);
            }
            catch (Exception ex)
            {
                errormessage = ex.Message;
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static List<ModelMatHangEntity> ConvertToList(DataTable dt)
        {
            try
            {
                return adapter.ConvertToList(dt);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }
    }
}